package com.eternallove.config.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分片任务扫描器配置
 * @author Eva.Caesar Liu
 * @since 2022/11/30 15:45
 */
@Configuration
public class SnippetScannerConfig {

    @Bean
    public JobDetail getSnippetScanner () {
        return JobBuilder.newJob(SnippetScanner.class)
                .withIdentity("snippetScanner")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger getSnippetScannerTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/1 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(getSnippetScanner())
                .withIdentity("snippetScannerTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
